package com.luckberry.murder.entity.good;

import com.alibaba.fastjson.JSON;
import com.luckberry.murder.entity.Script;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.Date;

@Data
@Builder
@AllArgsConstructor
// 交易订单
public class Order {

    private int oid;
    private int uid;    // 用户
    // good-商品 script-剧本 vip-会员
    private String type;    // 订单类型
    private double price;  // 购买价格
    private String content; // 订单内容
    private int count; // 交易数量
    private Date time;  // 交易时间

    public String getName() {
        switch (type) {
            case "good": {
                try {
                    return JSON.parseObject(content, Good.class).getName();
                } catch (Exception e) {
                    return "未知";
                }
            }
            case "script": {
                try {
                    return JSON.parseObject(content, Script.class).getName();
                } catch (Exception e) {
                    return "未知";
                }
            }
            case "vip":
                return "1个月会员";
        }
        return "未知";
    }

    public String transType() {
        switch (type) {
            case "good":
                return "商品";
            case "script":
                return "剧本";
            case "vip":
                return "会员";
        }
        return "未知";
    }
}
